//app.js
App({
  onLaunch: function () {
    //调用API从本地缓存中获取数据
    //var logs = wx.getStorageSync('logs') || []
    //logs.unshift(Date.now())
    //wx.setStorageSync('logs', logs)
  },
  getUserInfo: function (cb) {
    var that = this
    if (this.globalData.userInfo) {
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      //调用登录接口
      wx.login({
        success: function (r) {
          that.globalData.userCode = r.code;
          wx.getUserInfo({
            success: function (res) {
              that.globalData.userInfo = res.userInfo
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }
      })
    }
  },
  setUserSid: function (sid) {
    this.globalData.userSid = sid;
  },
  getUserSid: function () {
    return this.globalData.userSid;
  },
  setComId: function (comId) {
    this.globalData.comId = comId;
  },
  getComId: function () {
    return this.globalData.comId;
  },
  setOpenId(openId) {
    this.globalData.openId = openId;
  },
  getOpenId() {
    return this.globalData.openId;
  },
  getShop() {
    return this.globalData.shop;
  },
  setShop(shop) {
    this.globalData.shop = shop;
  },
  getHost() {
    return this.config.apiUrl;
  },
  setHost(host) {
    this.config.apiUrl = host;
  },
  getAlias() {
    return this.globalData.alias;
  },
  setAlias(alias) {
    this.globalData.alias = alias;
  },
  globalData: {
    alias: '',
    openId: null,
    userSid: '',

    userInfo: null,
    shop: null, //当前店铺信息
    userCode: null,
    comId: null
  },
  config: {
    // apiUrl: 'https://api.y.88ff.com',
    apiUrl: 'https://api.yun.taojinzi.cn'
  }
})